﻿using System;

/*Write a program that finds the sequence of maximal sum in given array. Example:
	{2, 3, -6, -1, 2, -1, 6, 4, -8, 8}  {2, -1, 6, 4}
	Can you do it with only one loop (with single scan through the elements of the array)?
*/

    class MaximalSum
    {
        static void Main()
        {
            int[] array = { 2, 3, -6, -1, 2, -1, 6, 4, -8, 8 };
            int maxSum = int.MinValue;
            int curSum = 0;
            

            for (int i = 0; i < array.Length-1; i++)
            {
                
                curSum = curSum + array[i];

                if (curSum > 0)
                {
                    curSum += array[i + 1];
                }
                else
                {
                    continue;
                }
                if (curSum > maxSum)
                {
                    maxSum = curSum;
                }
            }
            Console.WriteLine(maxSum);
        }
    }


   